/*
* ===================================================
*
*       Filename:  malloc.c
*
*
*        Created:  10/11/2011 06:38:48 PM
*       Revision:  none
*       Compiler:  gcc
*
*         Author:  durand_y, <durand.yoan@gmail.com>
*
* ===================================================
*/
#include "malloc.h"

s_map       *g_map_list;

void        *malloc(size_t size)
{
    void    *ptr = NULL;

    s_map   *map = NULL;

    if ((g_map_list == NULL))
    {
       create_map(size);
    }
    else
    {
        if ((ptr = find_next(g_map_list->block, g_map_list, size)) != NULL)
            return (ptr);
        else
        {
            create_map(size);
            map = g_map_list;
            while (map->next_map != NULL)
                map = map->next_map;
            return (map->block->end);
        }
    }
    return (g_map_list->block->end);
}
